// 个人设置页面
const app = getApp();

Page({
  data: {
    // 基本信息
    shopInfo: {
      logo: '',
      name: '',
      description: ''
    },
    // 个人信息
    userInfo: {
      name: '',
      phone: ''
    },
    // 登录状态
    isLogin: false
  },

  onLoad: function() {
    // 检查登录状态
    this.setData({
      isLogin: app.globalData.isLogin,
      userInfo: app.globalData.userInfo || {}
    });

    // 如果已登录，获取店铺信息
    if (app.globalData.isLogin) {
      this.getShopInfo();
    }
  },

  onShow: function() {
    // 页面显示时刷新登录状态
    this.setData({
      isLogin: app.globalData.isLogin,
      userInfo: app.globalData.userInfo || {}
    });
  },

  // 获取店铺信息
  getShopInfo: function() {
    wx.request({
      url: 'https://api.example.com/shop/info',
      header: {
        'Authorization': `Bearer ${app.globalData.token}`
      },
      success: (res) => {
        if (res.data.shop) {
          this.setData({
            shopInfo: res.data.shop
          });
        }
      }
    });
  },

  // 修改店铺信息
  editShopInfo: function() {
    wx.navigateTo({
      url: './edit-shop/edit-shop'
    });
  },

  // 查看服务条款
  viewTerms: function() {
    wx.navigateTo({
      url: '../terms/terms'
    });
  },

  // 查看隐私政策
  viewPrivacy: function() {
    wx.navigateTo({
      url: '../privacy/privacy'
    });
  },

  // 客服咨询
  contactService: function() {
    // 打开客服会话
    wx.openCustomerServiceChat({
      extInfo: { url: 'https://work.weixin.qq.com/kfid/kfc123456789' },
      corpId: 'wx123456789',
      success: () => {}
    });
  },

  // 退出登录
  logout: function() {
    wx.showModal({
      title: '提示',
      content: '确定要退出登录吗？',
      success: (res) => {
        if (res.confirm) {
          app.logout();
        }
      }
    });
  }
})